<%@ page contentType="text/html; charset=utf-8"%>
<%@ include file="/global/jsp-header.jsp"%>
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html">
<title>员工登陆</title>
<link href="/static/css/package.css" rel="stylesheet" />
<link href="/static/jquery/plugin/idealforms/css/jquery.idealforms.css"
	rel="stylesheet" />
<script src="/static/jquery/jquery-1.7.1.min.js" type="text/javascript"></script>
<script src="/static/jquery/jquery.cookie.js" type="text/javascript"></script>
<script
	src="/static/jquery/plugin/idealforms/js/jquery.idealforms.min.js"
	type="text/javascript"></script>
<script src="/static/jquery/plugin/idealforms/js/i18n/errors_cn.js"
	type="text/javascript"></script>
<style type="text/css">
body {
	margin: 0 auot;
	text-align: center;
}

div.container {
	height: 200px;
	width: 462px;
	top: 30%;
	left: 30%;
	margin: 0 auto;
	position: absolute;
}
</style>
<script type="text/javascript">
	$(function() {
		$(".myform").idealforms();
		<c:if test="${showCaptcha}">
		$(".pic").click(function(){
			$("#captchaPic").attr("src","/captcha.do?r=" + Math.random());
			return false;
		});
		
		function checkCaptcheValue(){
			var c = $("#captcha");
			var ckv = $.cookie("captcha");
			if(ckv){
				if(c.val()){
					var nkv = $.ajax({    
						type: "post",    
						url: "/get-captcha-answer.do",    
						cache: false,
						async: false,
						data: ({"captcha":c.val()})   
					}).responseText;
					if(nkv){
						if(ckv != nkv){
							return false;
						}else{
							$.cookie("captcha",nkv);
							return true;
						}
					}else{
						return false;
					}
				}
			}else{
				$.cookie("captcha","");
				return false;
			}
		}
		</c:if>
		$('#myform').submit(function(){
			if(!$('input[name=workerId]').val()){
				alert("请填写工号");
				return false;
			}else if(!$('input[name=password]').val()){
				alert("请填写密码");
				return false;
			}
			<c:if test="${showCaptcha}">
			if(!$("#captcha").val()){
				alert("请填写验证码");
				return false;
			}
			if(!checkCaptcheValue()){
				alert("验证码错误，请重新输入");
				return false;
			}
			</c:if>
		});
	});
</script>
</head>
<body>
	<div class="container">
		<div class="content">
			<%@include file="/global/action-messages.jsp"%>
			<form action="/login.do" name="myform" class="myform" id="myform"
				method="post">
				<input type="hidden" name="forward" value="${requestScope.forward}" />
				<div>
					<label class="required"> 员工工号: </label> <input type="text"
						size="40" name="workerId" class="required digits" value="110" />
				</div>
				<div>
					<label class="required"> 员工密码: </label> <input type="password"
						size="40" name="password" class="required password" value="123456" />
				</div>
				<c:if test="${showCaptcha}">
				<div>
					<label class="required"> 验证码: </label> <input type="text"
						size="40" name="captcha" id="captcha" class="required" value="" maxlength="4"/>
				</div>
				<div class="ideal-wrap">
					<label>&nbsp;</label>
        			<img class="pic" id="captchaPic" src="/captcha.do?r=<%=Math.random() %>"  alt="验证码" >
        			<label for="captchaPic"><a href="javascript:;" class="pic" id="changePic">看不清，换一张</a></label>
				</div>
				</c:if>
				<div>
					<label> &nbsp; </label> <input type="submit" value="登陆" /> <input
						type="reset" value="重置" />
				</div>
			</form>
		</div>
	</div>
</body>
</html>